﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MediaScraper.Common;
using MediaScraper.DataAccess.Entities;
using Microsoft.Win32;

namespace MediaScraper.DataAccess
{
    public class DataContext : DbContext
    {
        public DbSet<ProcessHistoryEntry> ProcessHistoryEntries { get; set; }
        public DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
        public DbSet<FileExtension> FileExtensions { get; set; }

        public DataContext()
        {

        }

    }

    public class DataContextSeedInitializer : DropCreateDatabaseAlways<DataContext>
    {
        protected override void Seed(DataContext context)
        {
            foreach (var extension in Constants.DefaultVideoExtensions)
            {
                context.FileExtensions.Add(new FileExtension() { ExtensionName = extension });
            }
            try
            {
                ApplicationConfiguration configuration = new ApplicationConfiguration();
                configuration.InstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\MediaScraper", "InstallPath", null);
                configuration.MovieRootPath = string.Empty;
                configuration.ShowRootPath = string.Empty;
                context.ApplicationConfigurations.Add(configuration);
            }
            catch (Exception ex)
            {
                //ToDo: Log
            }

            
            ProcessHistoryEntry processHistoryEntry = new ProcessHistoryEntry
                {
                    NewFilename = "Now You See Me (2013).mkv",
                    OldFileName = "Now.You.See.Me.2013.BDRip.X264-SPARKS.mkv",
                    OldPath = @"\\SERVER\\downloads\nysm-sparks",
                    NewPath = @"\\SERVER\\shows",
                    ProcessClassification = ProcessClassification.Success,
                    ProcessDate = DateTime.Now.AddHours(-5)
                };
            context.ProcessHistoryEntries.Add(processHistoryEntry);


            
            context.SaveChanges();
        }
    }
}
